import resolve from '@rollup/plugin-node-resolve';
import typescript from '@rollup/plugin-typescript';
import commonjs from '@rollup/plugin-commonjs';
import terser from '@rollup/plugin-terser';
import serve  from 'rollup-plugin-serve';//搭建本地服务器
import livereload from 'rollup-plugin-livereload';//监听文件变化，自动刷新浏览器

const port = 8000;
// eslint-disable-next-line no-undef
const isDev = process.env.NODE_ENV === 'development';
const devPlugins = isDev ? [
    serve({
        port,
        open: true,
        openPage: '/debug/index.html'
    }),
    livereload({
        port,
        watch: ['dist', 'debug']
    })
] : [];
export default [
	{
		input: './src/index.ts',
		output: {
			dir: 'dist',
			format: 'cjs',
			entryFileNames: '[name].cjs.js',
		},
		plugins: [
            resolve(), 
            commonjs(), 
            typescript(),
            terser(),
            ...devPlugins
        ],
	}, {
		input: './src/index.ts',
		output: {
			dir: 'dist',
			format: 'esm',
			entryFileNames: '[name].esm.js',
		},
		plugins: [
            resolve(), 
            commonjs(), 
            typescript(),
            terser()
        ],
	}
];